//
//  UIImageView+FZDefaultPlaceholder.m
//  Pods
//
//  Created by CyonLeuPro on 15/6/25.
//
//

#import "UIImageView+FZDefaultPlaceholder.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <SRCommonCategory/UIImage+Enhanced.h>

@implementation UIImageView (FZDefaultPlaceholder)

#pragma mark - Default Dubbing Image
- (void)fz_setAvatarImageWithUrlString:(NSString *)urlString
{
    NSURL *url = [NSURL URLWithString:urlString];
    [self fz_setImageWithAvatarDefaultPlaceholderWithURL:url placeholderSize:CGSizeZero];
}

- (void)fz_setImageWithDefaultPlaceholderWithURLString:(NSString *)urlString {
    NSURL *url = [NSURL URLWithString:urlString];
    [self fz_setImageWithDefaultPlaceholderWithURL:url];
}

- (void)fz_setImageWithDefaultPlaceholderWithURL:(NSURL *)url {
    [self fz_setImageWithDefaultPlaceholderWithURL:url placeholderSize:CGSizeZero progress:nil completed:nil];
}


- (void)fz_setHeaderImageWithCircle:(NSString *)url
{
    UIImage *placeholder = [[UIImage imageNamed:@"default_avatar"] circleImage];
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image == nil) return;
            
        self.image = [image circleImage];
    }];
}

- (void)fz_setImageWithDefaultPlaceholderWithURL:(NSURL *)url placeholderSize:(CGSize)size {
    [self fz_setImageWithDefaultPlaceholderWithURL:url placeholderSize:size progress:nil completed:nil];
}

- (void)fz_setImageWithDefaultPlaceholderWithURL:(NSURL *)url placeholderSize:(CGSize)size completed:(SDExternalCompletionBlock)completedBlock {
    [self fz_setImageWithDefaultPlaceholderWithURL:url placeholderSize:size progress:nil completed:completedBlock];
}


- (void)fz_setImageWithDefaultPlaceholderWithURL:(NSURL *)url placeholderSize:(CGSize)size progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDExternalCompletionBlock)completedBlock {
    
    [self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"defaultCourseCover"] options:SDWebImageRetryFailed progress:progressBlock completed:completedBlock];
}

- (void)fz_setImageWithURL:(NSURL *)url placeholder:(UIImage *)image completed:(SDExternalCompletionBlock)completedBlock {
    [self sd_setImageWithURL:url placeholderImage:image completed:completedBlock];
}

#pragma mark - Avatar Image

- (void)fz_setImageWithAvatarDefaultPlaceholderWithURL:(NSURL *)url placeholderSize:(CGSize)size {
    [self fz_setImageWithAvatarDefaultPlaceholderWithURL:url placeholderSize:size completed:nil];
}

- (void)fz_setImageWithAvatarDefaultPlaceholderWithURL:(NSURL *)url completed:(SDExternalCompletionBlock)completedBlock {
    [self sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_avatar"] completed:completedBlock];
}

- (void)fz_setImageWithAvatarDefaultPlaceholderWithURL:(NSURL *)url placeholderSize:(CGSize)size completed:(SDExternalCompletionBlock)completedBlock {
    [self fz_setImageWithURL:url placeholder:[UIImage imageNamed:@"default_avatar"]  completed:completedBlock];
}


@end
